#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc,char **argv){
  int n,i,j;
  int num_game;
   
  num_game=atoi(argv[1]);

  for(j=1;j<=num_game;++j){
    int bet=3000;
    int sum=0;
    int opponent_remain=10000;
    int self_remain=10000;
    int gain=0;
    int loss=0;
    int temp1=0;
    int temp2=0;

    printf("%d\n",bet); //1
    fflush(stdout);
    sum+=bet;
    scanf("%d",&n);

    for(i=2;i<=9;++i){
      //bet=(n>0?n-1:0);
      gain=gain+(bet<n?n:0);
      loss=loss+(bet<n?0:bet);

      opponent_remain=opponent_remain-n;
      self_remain=self_remain-bet;

      temp1=floor(opponent_remain/(11-i));
      temp2=floor(self_remain/(11-i));

      if(gain<=loss){  // opponent
        bet=((temp1>0||sum<10000)?(temp1<=10000-sum?temp1:10000-sum):0);
      }
      else{  // self
        bet=temp2;
      }
     
      printf("%d\n",bet); //2-9
      fflush(stdout);
      sum+=bet;
      scanf("%d",&n);
    }

    bet=10000-sum;
    printf("%d\n",bet); //10
    fflush(stdout);
    sum+=bet;
    scanf("%d",&n);
  }

  exit(EXIT_SUCCESS);
}